package com.firefightingiot.firefightingiot.web.web;

import cn.hutool.json.JSONObject;
import com.firefightingiot.firefightingiot.common.base.BaseController;
import com.firefightingiot.firefightingiot.support.annotaion.Action;
import com.firefightingiot.firefightingiot.support.annotaion.At;
import com.firefightingiot.firefightingiot.support.model.RespEntity;
import com.firefightingiot.firefightingiot.support.utils.DayUtil;
import com.firefightingiot.firefightingiot.web.service.HomeDataService;
import com.firefightingiot.firefightingiot.web.service.HomePageDataService;
import com.firefightingiot.firefightingiot.web.service.IotService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * 消防物联网首页数据统计控制器
 */
@Action
@RequestMapping(value="firefightingiot")
public class IotController extends BaseController {
    @Resource
    public IotService iotService;
    @Resource
    private HomePageDataService homePageDataService;
    /**
     * 今日报警
     * @param
     * @return
     */
    @At(value = "todayAlarm", method = RequestMethod.GET)
    public RespEntity todayAlarm(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.todayAlarm(jsonParam);
    }

    /**
     * 一周报警
     * @param
     * @return
     */
    @At(value = "weekAlarm", method = RequestMethod.GET)
    public RespEntity weekAlarm(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.weekAlarm(jsonParam);
    }
    /**
     * 一个月报警
     * @param
     * @return
     */
    @At(value = "monthAlarmLog", method = RequestMethod.GET)
    public RespEntity monthAlarmLog(@RequestBody(required = false) JSONObject jsonParam) {
        return homePageDataService.monthAlarmLog(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 七天报警数据不包括当天
     * @Date Created in 9:25 2022/6/8
     * @Param [jsonParam]
     */

    @At(value = "weekAlarmLog", method = RequestMethod.GET)
    public RespEntity weekAlarmLog(@RequestBody(required = false) JSONObject jsonParam) {
        return homePageDataService.weekAlarmLog(jsonParam);
    }
    /**
     * 实时报警列表
     * @param
     * @return
     */
    @At(value = "realTimeAlarm", method = RequestMethod.GET)
    public RespEntity realTimeAlarm(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.realTimeAlarm(jsonParam);
    }

    /**
     * 根据设备当前状态查询
     * @param
     * @return
     */
    @At(value = "todayDeviceCountByState", method = RequestMethod.GET)
    public RespEntity todayDeviceCountByState(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.todayDeviceCountByState(jsonParam);
    }

    /**
     * 报警单位分析
     * @param
     * @return
     */
    @At(value = "alarmBusinessAnalysis", method = RequestMethod.GET)
    public RespEntity alarmBusinessAnalysis(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.alarmBusinessAnalysis(jsonParam);
    }

    /**
     * 报警设备统计分析（top5）
     * @param
     * @return
     */
    @At(value = "getDeviceAlarmCount", method = RequestMethod.GET)
    public RespEntity getDeviceAlarmCount(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.getDeviceAlarmCount(jsonParam);
    }

    /**
     * web端大数据排行接口
     * @param
     * @return
     */
    @At(value = "webBigData", method = RequestMethod.GET)
    public RespEntity webBigData(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.webBigData(jsonParam);
    }

    /**
     * web端大数据下方分类统计
     * @param
     * @return
     */
    @At(value = "webBigDataForClassify", method = RequestMethod.GET)
    public RespEntity webBigDataForClassify(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.webBigDataForClassify(jsonParam);
    }

    /**
     * 可视化统计今日报警
     * @param
     * @return
     */
    @At(value = "visualizationTodayAlarm", method = RequestMethod.GET)
    public RespEntity visualizationTodayAlarm(@RequestBody(required = false) JSONObject jsonParam) {
        return iotService.visualizationTodayAlarm(jsonParam);
    }


    @Resource
    HomeDataService homeDataService;
    /**
     * 测试1
     * @param
     * @return
     */
    @At(value = "insertLogStatisticsForOne", method = RequestMethod.POST)
    public RespEntity insertLogStatisticsForOne(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        ///this.messageProducer.sendMessage(jsonParam);
        homeDataService.insertLogStatisticsForOne();
        return RespEntity.success();
    }
    @At(value = "test", method = RequestMethod.GET)
    public void test(@RequestBody(required = false) JSONObject jsonParam) throws InterruptedException {
        homePageDataService.insertMonthLogStatisticsForToday();
    }
    /**
     * 测试1
     * @param
     * @return
     */
    @At(value = "insertLogStatisticsForToday", method = RequestMethod.POST)
    public RespEntity insertLogStatisticsForToday(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        ///this.messageProducer.sendMessage(jsonParam);
        //生成昨天的统计记录
//        homeDataService.insertLogStatisticsForToday();
        JSONObject jsonObject = new JSONObject();
        //删除月统计数据
//        if(DayUtil.isTwoOfMonth()){
//            //删除前天之前的数据
//            jsonObject.put("monthStartDate",DayUtil.getBeforeYestoday());
//            homeDataService.deleteDataForStatisticsMonth(jsonObject);
//        }
        //赋值alldate,删除周统计数据：
//        jsonObject.put("alldate",DayUtil.getPastDate(6));
//        homeDataService.deleteDataForStatisticsWeek(jsonObject);
        return RespEntity.success();
    }

    /**
     * 测试1
     * @param
     * @return
     */
    @At(value = "deleteTodayLog", method = RequestMethod.POST)
    public RespEntity deleteTodayLog(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        ///this.messageProducer.sendMessage(jsonParam);
        JSONObject jsonObject = new JSONObject();
        //获取昨天的日期
        jsonObject.put("alarmtime", DayUtil.getYestoday());
        homeDataService.deleteTodayLog(jsonObject);
        return RespEntity.success();
    }



   
}
